package com.punai.gk.controller;

import com.punai.common.annotation.Log;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.page.TableDataInfo;
import com.punai.common.enums.BusinessType;
import com.punai.gk.domain.GkItem;
import com.punai.gk.service.IGkItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 归口字段定义Controller
 * 
 * @author zxw_
 * @date 2023-01-06
 */
@RestController
@RequestMapping("/gk/item")
public class GkItemController extends BaseController
{
    @Autowired
    private IGkItemService gkItemService;

    /**
     * 查询归口字段定义列表
     */
//    @PreAuthorize("@ss.hasPermi('gk:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(GkItem gkItem)
    {
        startPage();
        List<GkItem> list = gkItemService.selectGkItemList(gkItem);
        return getDataTable(list);
    }

    /**
     * 获取归口字段定义详细信息
     */
//    @PreAuthorize("@ss.hasPermi('gk:item:query')")
    @GetMapping(value = "/{templateId}/{id}")
    public AjaxResult getInfo(@PathVariable("templateId") String templateId,@PathVariable("id") String id)
    {
        return AjaxResult.success(gkItemService.selectGkItemById(templateId,id));
    }


    /**
     * 获取归口字段定义详细信息
     */
//    @PreAuthorize("@ss.hasPermi('gk:item:query')")
    @GetMapping(value = "/getMaxCode/{templateId}")
    public AjaxResult getMaxCode(@PathVariable("templateId") String templateId)
    {
        return AjaxResult.success("操作成功",gkItemService.getMaxCode(templateId));
    }

    /**
     * 新增归口字段定义
     */
//    @PreAuthorize("@ss.hasPermi('gk:item:add')")
    @Log(title = "归口字段定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GkItem gkItem)
    {
        return toAjax(gkItemService.insertGkItem(gkItem));
    }

    /**
     * 修改归口字段定义
     */
//    @PreAuthorize("@ss.hasPermi('gk:item:edit')")
    @Log(title = "归口字段定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GkItem gkItem)
    {
        return toAjax(gkItemService.updateGkItem(gkItem));
    }

    /**
     * 删除归口字段定义
     */
//    @PreAuthorize("@ss.hasPermi('gk:item:remove')")
    @Log(title = "归口字段定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templateId}/{id}")
    public AjaxResult remove(@PathVariable("templateId") String templateId,@PathVariable("id") String id)
    {
        return toAjax(gkItemService.deleteGkItemById(templateId,id));
    }

    /**
     * 获取归口数据详细信息
     */
    @GetMapping(value = "/gkHeaderList/{id}")
    public AjaxResult gkHeaderList(@PathVariable("id") String id)
    {
        return AjaxResult.success("gkUseDataService.gkHeaderList(id)");
    }
}
